<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>mainwindow.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-mainwindows-mdi-example.html">MDI Example</a></td><td >mainwindow.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">mainwindow.cpp 示例文件</h1>
<span class="subtitle">mainwindows/mdi/mainwindow.cpp</span>
<!-- $$$mainwindows/mdi/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="preprocessor">#include &quot;mainwindow.h&quot;</span>
  <span class="preprocessor">#include &quot;mdichild.h&quot;</span>

  MainWindow<span class="operator">::</span>MainWindow()
      : mdiArea(<span class="keyword">new</span> <span class="type"><a href="qmdiarea.html">QMdiArea</a></span>)
  {
      mdiArea<span class="operator">-</span><span class="operator">&gt;</span>setHorizontalScrollBarPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ScrollBarAsNeeded);
      mdiArea<span class="operator">-</span><span class="operator">&gt;</span>setVerticalScrollBarPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ScrollBarAsNeeded);
      setCentralWidget(mdiArea);
      connect(mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>subWindowActivated<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>updateMenus);

      createActions();
      createStatusBar();
      updateMenus();

      readSettings();

      setWindowTitle(tr(<span class="string">&quot;MDI&quot;</span>));
      setUnifiedTitleAndToolBarOnMac(<span class="keyword">true</span>);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>closeEvent(<span class="type"><a href="../qtgui/qcloseevent.html">QCloseEvent</a></span> <span class="operator">*</span>event)
  {
      mdiArea<span class="operator">-</span><span class="operator">&gt;</span>closeAllSubWindows();
      <span class="keyword">if</span> (mdiArea<span class="operator">-</span><span class="operator">&gt;</span>currentSubWindow()) {
          event<span class="operator">-</span><span class="operator">&gt;</span>ignore();
      } <span class="keyword">else</span> {
          writeSettings();
          event<span class="operator">-</span><span class="operator">&gt;</span>accept();
      }
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>newFile()
  {
      MdiChild <span class="operator">*</span>child <span class="operator">=</span> createMdiChild();
      child<span class="operator">-</span><span class="operator">&gt;</span>newFile();
      child<span class="operator">-</span><span class="operator">&gt;</span>show();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>open()
  {
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getOpenFileName(<span class="keyword">this</span>);
      <span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>isEmpty())
          openFile(fileName);
  }

  bool MainWindow<span class="operator">::</span>openFile(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName)
  {
      <span class="keyword">if</span> (<span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span>existing <span class="operator">=</span> findMdiChild(fileName)) {
          mdiArea<span class="operator">-</span><span class="operator">&gt;</span>setActiveSubWindow(existing);
          <span class="keyword">return</span> <span class="keyword">true</span>;
      }
      <span class="keyword">const</span> bool succeeded <span class="operator">=</span> loadFile(fileName);
      <span class="keyword">if</span> (succeeded)
          statusBar()<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;File loaded&quot;</span>)<span class="operator">,</span> <span class="number">2000</span>);
      <span class="keyword">return</span> succeeded;
  }

  bool MainWindow<span class="operator">::</span>loadFile(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName)
  {
      MdiChild <span class="operator">*</span>child <span class="operator">=</span> createMdiChild();
      <span class="keyword">const</span> bool succeeded <span class="operator">=</span> child<span class="operator">-</span><span class="operator">&gt;</span>loadFile(fileName);
      <span class="keyword">if</span> (succeeded)
          child<span class="operator">-</span><span class="operator">&gt;</span>show();
      <span class="keyword">else</span>
          child<span class="operator">-</span><span class="operator">&gt;</span>close();
      MainWindow<span class="operator">::</span>prependToRecentFiles(fileName);
      <span class="keyword">return</span> succeeded;
  }

  <span class="keyword">static</span> <span class="keyword">inline</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> recentFilesKey() { <span class="keyword">return</span> <span class="type"><a href="../qtcore/qstring.html#QStringLiteral">QStringLiteral</a></span>(<span class="string">&quot;recentFileList&quot;</span>); }
  <span class="keyword">static</span> <span class="keyword">inline</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileKey() { <span class="keyword">return</span> <span class="type"><a href="../qtcore/qstring.html#QStringLiteral">QStringLiteral</a></span>(<span class="string">&quot;file&quot;</span>); }

  <span class="keyword">static</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> readRecentFiles(<span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> <span class="operator">&amp;</span>settings)
  {
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> result;
      <span class="keyword">const</span> <span class="type">int</span> count <span class="operator">=</span> settings<span class="operator">.</span>beginReadArray(recentFilesKey());
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> count; <span class="operator">+</span><span class="operator">+</span>i) {
          settings<span class="operator">.</span>setArrayIndex(i);
          result<span class="operator">.</span>append(settings<span class="operator">.</span>value(fileKey())<span class="operator">.</span>toString());
      }
      settings<span class="operator">.</span>endArray();
      <span class="keyword">return</span> result;
  }

  <span class="keyword">static</span> <span class="type">void</span> writeRecentFiles(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> <span class="operator">&amp;</span>files<span class="operator">,</span> <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> <span class="operator">&amp;</span>settings)
  {
      <span class="keyword">const</span> <span class="type">int</span> count <span class="operator">=</span> files<span class="operator">.</span>size();
      settings<span class="operator">.</span>beginWriteArray(recentFilesKey());
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> count; <span class="operator">+</span><span class="operator">+</span>i) {
          settings<span class="operator">.</span>setArrayIndex(i);
          settings<span class="operator">.</span>setValue(fileKey()<span class="operator">,</span> files<span class="operator">.</span>at(i));
      }
      settings<span class="operator">.</span>endArray();
  }

  bool MainWindow<span class="operator">::</span>hasRecentFiles()
  {
      <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> settings(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>organizationName()<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>applicationName());
      <span class="keyword">const</span> <span class="type">int</span> count <span class="operator">=</span> settings<span class="operator">.</span>beginReadArray(recentFilesKey());
      settings<span class="operator">.</span>endArray();
      <span class="keyword">return</span> count <span class="operator">&gt;</span> <span class="number">0</span>;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>prependToRecentFiles(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName)
  {
      <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> settings(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>organizationName()<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>applicationName());

      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> oldRecentFiles <span class="operator">=</span> readRecentFiles(settings);
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> recentFiles <span class="operator">=</span> oldRecentFiles;
      recentFiles<span class="operator">.</span>removeAll(fileName);
      recentFiles<span class="operator">.</span>prepend(fileName);
      <span class="keyword">if</span> (oldRecentFiles <span class="operator">!</span><span class="operator">=</span> recentFiles)
          writeRecentFiles(recentFiles<span class="operator">,</span> settings);

      setRecentFilesVisible(<span class="operator">!</span>recentFiles<span class="operator">.</span>isEmpty());
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>setRecentFilesVisible(bool visible)
  {
      recentFileSubMenuAct<span class="operator">-</span><span class="operator">&gt;</span>setVisible(visible);
      recentFileSeparator<span class="operator">-</span><span class="operator">&gt;</span>setVisible(visible);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>updateRecentFileActions()
  {
      <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> settings(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>organizationName()<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>applicationName());

      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> recentFiles <span class="operator">=</span> readRecentFiles(settings);
      <span class="keyword">const</span> <span class="type">int</span> count <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(<span class="type">int</span>(MaxRecentFiles)<span class="operator">,</span> recentFiles<span class="operator">.</span>size());
      <span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>;
      <span class="keyword">for</span> ( ; i <span class="operator">&lt;</span> count; <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span>(recentFiles<span class="operator">.</span>at(i))<span class="operator">.</span>fileName();
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span><span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;&amp;%1 %2&quot;</span>)<span class="operator">.</span>arg(i <span class="operator">+</span> <span class="number">1</span>)<span class="operator">.</span>arg(fileName));
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span><span class="operator">-</span><span class="operator">&gt;</span>setData(recentFiles<span class="operator">.</span>at(i));
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span><span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="keyword">true</span>);
      }
      <span class="keyword">for</span> ( ; i <span class="operator">&lt;</span> MaxRecentFiles; <span class="operator">+</span><span class="operator">+</span>i)
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span><span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="keyword">false</span>);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>openRecentFile()
  {
      <span class="keyword">if</span> (<span class="keyword">const</span> <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(sender()))
          openFile(action<span class="operator">-</span><span class="operator">&gt;</span>data()<span class="operator">.</span>toString());
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>save()
  {
      <span class="keyword">if</span> (activeMdiChild() <span class="operator">&amp;</span><span class="operator">&amp;</span> activeMdiChild()<span class="operator">-</span><span class="operator">&gt;</span>save())
          statusBar()<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;File saved&quot;</span>)<span class="operator">,</span> <span class="number">2000</span>);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>saveAs()
  {
      MdiChild <span class="operator">*</span>child <span class="operator">=</span> activeMdiChild();
      <span class="keyword">if</span> (child <span class="operator">&amp;</span><span class="operator">&amp;</span> child<span class="operator">-</span><span class="operator">&gt;</span>saveAs()) {
          statusBar()<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;File saved&quot;</span>)<span class="operator">,</span> <span class="number">2000</span>);
          MainWindow<span class="operator">::</span>prependToRecentFiles(child<span class="operator">-</span><span class="operator">&gt;</span>currentFile());
      }
  }

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
  <span class="type">void</span> MainWindow<span class="operator">::</span>cut()
  {
      <span class="keyword">if</span> (activeMdiChild())
          activeMdiChild()<span class="operator">-</span><span class="operator">&gt;</span>cut();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>copy()
  {
      <span class="keyword">if</span> (activeMdiChild())
          activeMdiChild()<span class="operator">-</span><span class="operator">&gt;</span>copy();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>paste()
  {
      <span class="keyword">if</span> (activeMdiChild())
          activeMdiChild()<span class="operator">-</span><span class="operator">&gt;</span>paste();
  }
  <span class="preprocessor">#endif</span>

  <span class="type">void</span> MainWindow<span class="operator">::</span>about()
  {
     <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>about(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">&quot;About MDI&quot;</span>)<span class="operator">,</span>
              tr(<span class="string">&quot;The &lt;b&gt;MDI&lt;/b&gt; example demonstrates how to write multiple &quot;</span>
                 <span class="string">&quot;document interface applications using Qt.&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>updateMenus()
  {
      bool hasMdiChild <span class="operator">=</span> (activeMdiChild() <span class="operator">!</span><span class="operator">=</span> <span class="number">0</span>);
      saveAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      saveAsAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      pasteAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
  <span class="preprocessor">#endif</span>
      closeAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      closeAllAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      tileAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      cascadeAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      nextAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      previousAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasMdiChild);
      windowMenuSeparatorAct<span class="operator">-</span><span class="operator">&gt;</span>setVisible(hasMdiChild);

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      bool hasSelection <span class="operator">=</span> (activeMdiChild() <span class="operator">&amp;</span><span class="operator">&amp;</span>
                           activeMdiChild()<span class="operator">-</span><span class="operator">&gt;</span>textCursor()<span class="operator">.</span>hasSelection());
      cutAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasSelection);
      copyAct<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(hasSelection);
  <span class="preprocessor">#endif</span>
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>updateWindowMenu()
  {
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>clear();
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(closeAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(closeAllAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tileAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(cascadeAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(nextAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(previousAct);
      windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(windowMenuSeparatorAct);

      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span><span class="operator">&gt;</span> windows <span class="operator">=</span> mdiArea<span class="operator">-</span><span class="operator">&gt;</span>subWindowList();
      windowMenuSeparatorAct<span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="operator">!</span>windows<span class="operator">.</span>isEmpty());

      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> windows<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span>mdiSubWindow <span class="operator">=</span> windows<span class="operator">.</span>at(i);
          MdiChild <span class="operator">*</span>child <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MdiChild <span class="operator">*</span><span class="operator">&gt;</span>(mdiSubWindow<span class="operator">-</span><span class="operator">&gt;</span>widget());

          <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text;
          <span class="keyword">if</span> (i <span class="operator">&lt;</span> <span class="number">9</span>) {
              text <span class="operator">=</span> tr(<span class="string">&quot;&amp;%1 %2&quot;</span>)<span class="operator">.</span>arg(i <span class="operator">+</span> <span class="number">1</span>)
                                 <span class="operator">.</span>arg(child<span class="operator">-</span><span class="operator">&gt;</span>userFriendlyCurrentFile());
          } <span class="keyword">else</span> {
              text <span class="operator">=</span> tr(<span class="string">&quot;%1 %2&quot;</span>)<span class="operator">.</span>arg(i <span class="operator">+</span> <span class="number">1</span>)
                                <span class="operator">.</span>arg(child<span class="operator">-</span><span class="operator">&gt;</span>userFriendlyCurrentFile());
          }
          <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action <span class="operator">=</span> windowMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(text<span class="operator">,</span> mdiSubWindow<span class="operator">,</span> <span class="operator">[</span><span class="keyword">this</span><span class="operator">,</span> mdiSubWindow<span class="operator">]</span>() {
              mdiArea<span class="operator">-</span><span class="operator">&gt;</span>setActiveSubWindow(mdiSubWindow);
          });
          action<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
          action <span class="operator">-</span><span class="operator">&gt;</span>setChecked(child <span class="operator">=</span><span class="operator">=</span> activeMdiChild());
      }
  }

  MdiChild <span class="operator">*</span>MainWindow<span class="operator">::</span>createMdiChild()
  {
      MdiChild <span class="operator">*</span>child <span class="operator">=</span> <span class="keyword">new</span> MdiChild;
      mdiArea<span class="operator">-</span><span class="operator">&gt;</span>addSubWindow(child);

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      connect(child<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qtextedit.html">QTextEdit</a></span><span class="operator">::</span>copyAvailable<span class="operator">,</span> cutAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>setEnabled);
      connect(child<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qtextedit.html">QTextEdit</a></span><span class="operator">::</span>copyAvailable<span class="operator">,</span> copyAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>setEnabled);
  <span class="preprocessor">#endif</span>

      <span class="keyword">return</span> child;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>createActions()
  {
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;File&quot;</span>));
      <span class="type"><a href="qtoolbar.html">QToolBar</a></span> <span class="operator">*</span>fileToolBar <span class="operator">=</span> addToolBar(tr(<span class="string">&quot;File&quot;</span>));

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> newIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;document-new&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/new.png&quot;</span>));
      newAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(newIcon<span class="operator">,</span> tr(<span class="string">&quot;&amp;New&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      newAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>New);
      newAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Create a new file&quot;</span>));
      connect(newAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>newFile);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(newAct);
      fileToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(newAct);

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> openIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;document-open&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/open.png&quot;</span>));
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>openAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(openIcon<span class="operator">,</span> tr(<span class="string">&quot;&amp;Open...&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      openAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Open);
      openAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Open an existing file&quot;</span>));
      connect(openAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>open);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(openAct);
      fileToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(openAct);

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> saveIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;document-save&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/save.png&quot;</span>));
      saveAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(saveIcon<span class="operator">,</span> tr(<span class="string">&quot;&amp;Save&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      saveAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Save);
      saveAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Save the document to disk&quot;</span>));
      connect(saveAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>save);
      fileToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(saveAct);

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> saveAsIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;document-save-as&quot;</span>);
      saveAsAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(saveAsIcon<span class="operator">,</span> tr(<span class="string">&quot;Save &amp;As...&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      saveAsAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>SaveAs);
      saveAsAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Save the document under a new name&quot;</span>));
      connect(saveAsAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>saveAs);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(saveAsAct);

      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();

      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>recentMenu <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;Recent...&quot;</span>));
      connect(recentMenu<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmenu.html">QMenu</a></span><span class="operator">::</span>aboutToShow<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>updateRecentFileActions);
      recentFileSubMenuAct <span class="operator">=</span> recentMenu<span class="operator">-</span><span class="operator">&gt;</span>menuAction();

      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> MaxRecentFiles; <span class="operator">+</span><span class="operator">+</span>i) {
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">=</span> recentMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>()<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>openRecentFile);
          recentFileActs<span class="operator">[</span>i<span class="operator">]</span><span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="keyword">false</span>);
      }

      recentFileSeparator <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();

      setRecentFilesVisible(MainWindow<span class="operator">::</span>hasRecentFiles());

      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;Switch layout direction&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>switchLayoutDirection);

      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> exitIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;application-exit&quot;</span>);
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>exitAct <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(exitIcon<span class="operator">,</span> tr(<span class="string">&quot;E&amp;xit&quot;</span>)<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>closeAllWindows);
      exitAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Quit);
      exitAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Exit the application&quot;</span>));
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(exitAct);

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>editMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Edit&quot;</span>));
      <span class="type"><a href="qtoolbar.html">QToolBar</a></span> <span class="operator">*</span>editToolBar <span class="operator">=</span> addToolBar(tr(<span class="string">&quot;Edit&quot;</span>));

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> cutIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;edit-cut&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/cut.png&quot;</span>));
      cutAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(cutIcon<span class="operator">,</span> tr(<span class="string">&quot;Cu&amp;t&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      cutAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Cut);
      cutAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Cut the current selection's contents to the &quot;</span>
                              <span class="string">&quot;clipboard&quot;</span>));
      connect(cutAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>cut);
      editMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(cutAct);
      editToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(cutAct);

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> copyIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;edit-copy&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/copy.png&quot;</span>));
      copyAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(copyIcon<span class="operator">,</span> tr(<span class="string">&quot;&amp;Copy&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      copyAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Copy);
      copyAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Copy the current selection's contents to the &quot;</span>
                               <span class="string">&quot;clipboard&quot;</span>));
      connect(copyAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>copy);
      editMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(copyAct);
      editToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(copyAct);

      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> pasteIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">&quot;edit-paste&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">&quot;:/images/paste.png&quot;</span>));
      pasteAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(pasteIcon<span class="operator">,</span> tr(<span class="string">&quot;&amp;Paste&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      pasteAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Paste);
      pasteAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Paste the clipboard's contents into the current &quot;</span>
                                <span class="string">&quot;selection&quot;</span>));
      connect(pasteAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>paste);
      editMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(pasteAct);
      editToolBar<span class="operator">-</span><span class="operator">&gt;</span>addAction(pasteAct);
  <span class="preprocessor">#endif</span>

      windowMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Window&quot;</span>));
      connect(windowMenu<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmenu.html">QMenu</a></span><span class="operator">::</span>aboutToShow<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>updateWindowMenu);

      closeAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Cl&amp;ose&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      closeAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Close the active window&quot;</span>));
      connect(closeAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span>
              mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>closeActiveSubWindow);

      closeAllAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Close &amp;All&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      closeAllAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Close all the windows&quot;</span>));
      connect(closeAllAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>closeAllSubWindows);

      tileAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Tile&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      tileAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Tile the windows&quot;</span>));
      connect(tileAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>tileSubWindows);

      cascadeAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Cascade&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      cascadeAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Cascade the windows&quot;</span>));
      connect(cascadeAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>cascadeSubWindows);

      nextAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Ne&amp;xt&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      nextAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>NextChild);
      nextAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Move the focus to the next window&quot;</span>));
      connect(nextAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>activateNextSubWindow);

      previousAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Pre&amp;vious&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      previousAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>PreviousChild);
      previousAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Move the focus to the previous &quot;</span>
                                   <span class="string">&quot;window&quot;</span>));
      connect(previousAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> mdiArea<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qmdiarea.html">QMdiArea</a></span><span class="operator">::</span>activatePreviousSubWindow);

      windowMenuSeparatorAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(<span class="keyword">this</span>);
      windowMenuSeparatorAct<span class="operator">-</span><span class="operator">&gt;</span>setSeparator(<span class="keyword">true</span>);

      updateWindowMenu();

      menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();

      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>helpMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Help&quot;</span>));

      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>aboutAct <span class="operator">=</span> helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;&amp;About&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>about);
      aboutAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Show the application's About box&quot;</span>));

      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>aboutQtAct <span class="operator">=</span> helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;About &amp;Qt&quot;</span>)<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>aboutQt);
      aboutQtAct<span class="operator">-</span><span class="operator">&gt;</span>setStatusTip(tr(<span class="string">&quot;Show the Qt library's About box&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>createStatusBar()
  {
      statusBar()<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;Ready&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>readSettings()
  {
      <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> settings(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>organizationName()<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>applicationName());
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> geometry <span class="operator">=</span> settings<span class="operator">.</span>value(<span class="string">&quot;geometry&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span>())<span class="operator">.</span>toByteArray();
      <span class="keyword">if</span> (geometry<span class="operator">.</span>isEmpty()) {
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> availableGeometry <span class="operator">=</span> <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>desktop()<span class="operator">-</span><span class="operator">&gt;</span>availableGeometry(<span class="keyword">this</span>);
          resize(availableGeometry<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">3</span><span class="operator">,</span> availableGeometry<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span>);
          move((availableGeometry<span class="operator">.</span>width() <span class="operator">-</span> width()) <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span>
               (availableGeometry<span class="operator">.</span>height() <span class="operator">-</span> height()) <span class="operator">/</span> <span class="number">2</span>);
      } <span class="keyword">else</span> {
          restoreGeometry(geometry);
      }
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>writeSettings()
  {
      <span class="type"><a href="../qtcore/qsettings.html">QSettings</a></span> settings(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>organizationName()<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>applicationName());
      settings<span class="operator">.</span>setValue(<span class="string">&quot;geometry&quot;</span><span class="operator">,</span> saveGeometry());
  }

  MdiChild <span class="operator">*</span>MainWindow<span class="operator">::</span>activeMdiChild() <span class="keyword">const</span>
  {
      <span class="keyword">if</span> (<span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span>activeSubWindow <span class="operator">=</span> mdiArea<span class="operator">-</span><span class="operator">&gt;</span>activeSubWindow())
          <span class="keyword">return</span> qobject_cast<span class="operator">&lt;</span>MdiChild <span class="operator">*</span><span class="operator">&gt;</span>(activeSubWindow<span class="operator">-</span><span class="operator">&gt;</span>widget());
      <span class="keyword">return</span> <span class="number">0</span>;
  }

  <span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span>MainWindow<span class="operator">::</span>findMdiChild(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName) <span class="keyword">const</span>
  {
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> canonicalFilePath <span class="operator">=</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span>(fileName)<span class="operator">.</span>canonicalFilePath();

      foreach (<span class="type"><a href="qmdisubwindow.html">QMdiSubWindow</a></span> <span class="operator">*</span>window<span class="operator">,</span> mdiArea<span class="operator">-</span><span class="operator">&gt;</span>subWindowList()) {
          MdiChild <span class="operator">*</span>mdiChild <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MdiChild <span class="operator">*</span><span class="operator">&gt;</span>(window<span class="operator">-</span><span class="operator">&gt;</span>widget());
          <span class="keyword">if</span> (mdiChild<span class="operator">-</span><span class="operator">&gt;</span>currentFile() <span class="operator">=</span><span class="operator">=</span> canonicalFilePath)
              <span class="keyword">return</span> window;
      }
      <span class="keyword">return</span> <span class="number">0</span>;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>switchLayoutDirection()
  {
      <span class="keyword">if</span> (layoutDirection() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>LeftToRight)
          <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>setLayoutDirection(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>RightToLeft);
      <span class="keyword">else</span>
          <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>setLayoutDirection(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>LeftToRight);
  }

</pre>
</div>
<!-- @@@mainwindows/mdi/mainwindow.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
